{
    
    // 加载模块
    let utils = (typeof(global) === "undefined") ? window.utils : global.utils;
    
    /**
     * WebSocket 封装
     * 试图把标准html5中的 WebSocket 和 微信中的 wx.connectSocket() 接口统一封装成一个兼容的版本，屏蔽运行环境的差异
     */
    let wskt = {}

    /**
     * 打开 WebSocket
     * eventHandlers:
     * onError   : function(errMmsg)
     * onOpen    : function()
     * onMessage : function(msg)
     * onClose   : function()
     */
    wskt.open = function(url, eventHandlers)  {
        let skt;
        if((typeof(window) != "undefined") && utils.notEmpty(window.WebSocket)) {
            skt = new WebSocket(url);
            skt.onerror         = eventHandlers.onError;
            skt.onopen          = eventHandlers.onOpen;
            skt.onmessage       = eventHandlers.onMessage;
            skt.onclose         = eventHandlers.onClose;
        } else if((typeof(wx) != "undefined") && utils.notEmpty(wx.connectSocket)) {
            skt = wx.connectSocket(url);
            skt.onError   		= eventHandlers.onError;
            skt.onOpen    		= eventHandlers.onOpen;
            skt.onSocketMessage = eventHandlers.onMessage;
            skt.onClose   		= eventHandlers.onClose;
        } else {
            throw("当前运行环境不支持 WebSocket !");
        }
        
        return skt;
    };

    // 把模块放到全局命名空间中去
    (function(){
        return (typeof global !== "undefined") ? global :
            (typeof self !== "undefined") ? self :
            (typeof window !== "undefined") ? window : {};
    })()["wskt"] = wskt;

}
